#include"../source/server.hpp"

void OnConnected(const PtrConnection& conn){
    DEB_LOG("New conntection:%p",conn.get());
}
void OnClosed(const PtrConnection& conn){
    DEB_LOG("Close conntection:%p",conn.get());
}
void OnMessage(const PtrConnection& conn,Buffer* buffer){
    DEB_LOG("%s",buffer->ReadPosition());
    buffer->MoveReadOffset(buffer->ReadAbleSize());
    std::string str="This is an apple!";
    conn->Send(str.c_str(),str.size());
    // conn->Shutdown();   //这个开启的话，调用一次这个函数后这个tcp连接就会断开
}
int main()
{
    TcpServer server(8080);
    server.SetThreadCount(2);
    // server.EnableInactiveRelease(10);
    server.SetConnectedCallback(OnConnected);
    server.SetClosedCallback(OnClosed);
    server.SetMessageCallback(OnMessage);
    server.Start();
    return 0;
}